package com.atguigu.gulimall.order.vo;

import jdk.nashorn.internal.ir.CallNode;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @Classname OrderConfirmVo
 * @Description TODO
 * @Date 2021/10/14 9:56
 * @Author Anonymous
 */
@SuppressWarnings("all")
public class OrderConfirmVo {

    //收货人地址信息
    @Getter
    @Setter
    List<MemberAddressVo> addressVoList;

    //所有选中的购物项
    @Getter
    @Setter
    List<OrderItemVo> items;

    /**
     * 优惠券（会员积分）
     **/
    @Getter
    @Setter
    private Integer integration;

    //总金额
    private BigDecimal totalPrice;

    public BigDecimal getTotalPrice() {
        BigDecimal totalPrice = new BigDecimal(0);
        if (items != null) {
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                totalPrice = totalPrice.add(multiply);
            }
        }
        return totalPrice;
    }

    public Integer getCount() {
        Integer i = 0;
        if (items != null) {
            for (OrderItemVo item : items) {
               i += item.getCount();
            }
        }
        return i;
    }

    //应付金额
    private BigDecimal payPrice;

    public BigDecimal getPayPrice() {
        return getTotalPrice();
    }


    /**
     * 防止重复提交的令牌
     **/
    @Getter
    @Setter
    private String orderToken;

    @Getter
    @Setter
    Map<Long,Boolean> stocks;
}
